from pydantic import BaseModel
from typing import Optional, List, Generic, TypeVar

# Winery schemas
class WineryBase(BaseModel):
    name: str
    location: str
    contact: str
    description: Optional[str] = None

class WineryCreate(WineryBase):
    pass

class Winery(WineryBase):
    id: int
    class Config:
        from_attributes = True

# Vineyard schemas
class VineyardBase(BaseModel):
    name: str
    area: float
    grape_variety: str
    planting_year: str
    soil_type: str
    location: str

class VineyardCreate(VineyardBase):
    pass

class Vineyard(VineyardBase):
    id: int
    class Config:
        from_attributes = True

# Harvest schemas
class HarvestBase(BaseModel):
    vineyard_name: str
    harvest_date: str
    quantity: float
    quality_grade: str
    harvest_method: str
    weather: str
    notes: Optional[str] = None

class HarvestCreate(HarvestBase):
    pass

class Harvest(HarvestBase):
    id: int
    class Config:
        from_attributes = True

# Preprocessing schemas
class PreprocessingBase(BaseModel):
    batch_number: str
    process_date: str
    process_type: str
    temperature: float
    duration: float
    operator: str
    notes: Optional[str] = None

class PreprocessingCreate(PreprocessingBase):
    pass

class Preprocessing(PreprocessingBase):
    id: int
    class Config:
        from_attributes = True

# Fermentation schemas
class FermentationBase(BaseModel):
    batch_number: str
    start_date: str
    end_date: str
    temperature: float
    yeast_type: str
    alcohol_content: float
    status: str

class FermentationCreate(FermentationBase):
    pass

class Fermentation(FermentationBase):
    id: int
    class Config:
        from_attributes = True

# Storage schemas
class StorageBase(BaseModel):
    batch_number: str
    storage_date: str
    storage_type: str
    temperature: float
    humidity: float
    duration: str
    notes: Optional[str] = None

class StorageCreate(StorageBase):
    pass

class Storage(StorageBase):
    id: int
    class Config:
        from_attributes = True

# Bottling schemas
class BottlingBase(BaseModel):
    batch_number: str
    bottling_date: str
    bottle_type: str
    quantity: int
    label_info: str
    packaging_type: str
    notes: Optional[str] = None

class BottlingCreate(BottlingBase):
    pass

class Bottling(BottlingBase):
    id: int
    class Config:
        from_attributes = True

# QualityCheck schemas
class QualityCheckBase(BaseModel):
    batch_number: str
    check_date: str
    inspector: str
    alcohol_content: float
    acidity: float
    sugar_content: float
    result: str
    notes: Optional[str] = None

class QualityCheckCreate(QualityCheckBase):
    pass

class QualityCheck(QualityCheckBase):
    id: int
    class Config:
        from_attributes = True

# Order schemas
class OrderBase(BaseModel):
    order_number: str
    customer_name: str
    product_name: str
    quantity: int
    order_date: str
    delivery_date: str
    status: str
    notes: Optional[str] = None

class OrderCreate(OrderBase):
    pass

class Order(OrderBase):
    id: int
    class Config:
        from_attributes = True

# Logistics schemas
class LogisticsBase(BaseModel):
    tracking_number: str
    order_number: str
    carrier: str
    shipping_date: str
    delivery_date: str
    status: str
    notes: Optional[str] = None

class LogisticsCreate(LogisticsBase):
    pass

class Logistics(LogisticsBase):
    id: int
    class Config:
        from_attributes = True

# Operation Log
class OperationLogBase(BaseModel):
    entity: str
    action: str
    entity_id: int
    detail: Optional[str] = None
    timestamp: str
    operator: Optional[str] = None

class OperationLogCreate(OperationLogBase):
    pass

class OperationLog(OperationLogBase):
    id: int
    class Config:
        from_attributes = True

# Pagination
T = TypeVar('T')
class Page(BaseModel):
    total: int
    page: int
    size: int
    items: list
